package logic

import (
	"context"
	"edu/edurpc/edurpc"

	"edu/api/internal/svc"
	"edu/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ContentAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewContentAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ContentAddLogic {
	return &ContentAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ContentAddLogic) ContentAdd(req *types.ContentAddRequest) (resp *types.Response, err error) {
	content, err := l.svcCtx.EduRpc.ContentAdd(l.ctx, &edurpc.ContentAddRequest{
		UserId:  int64(req.UserId),
		NovelId: int64(req.NovelId),
		Context: req.Context,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "评价成功",
		Data:    content,
	}, nil
}
